<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>用户余额</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="../../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../../css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="../../css/animate.css" rel="stylesheet">
    <link href="../../css/plugins/ztree/style.css?v=4.1.0" rel="stylesheet">

</head>
<style type="text/css">
    .setOs{
        width: 20%;
        height: 26px;
    }
    div[class="bars pull-left"]{
        width: 90%;
    }
</style>
<body class="">
<div class="wrapper wrapper-content animated fadeInRight">
	
   <div id="toolbar" class="form-inline">
        <div class="">
        	<div class="form-group">
                <label for="name">用户:</label>
                <input type="text" placeholder="用户" id="name" class="form-control" disabled="disabled"/>
            </div>
            <div class="form-group">
                <label for="balance">账户余额:</label>
                <input type="text" placeholder="账户余额" id="balance" class="form-control" disabled="disabled"/>
            </div>
            <!-- <div class="form-group">
                <label for="lockBalance">锁定余额:</label>
                <input type="text" placeholder="锁定余额"  id="lockBalance" class="form-control" disabled="disabled"/>
            </div> -->
        </div>
    </div>  

    <table id="tb_dept" >
        <thead>
            <tr>
                <th data-checkbox="true"></th>
                <th data-field="amount" data-formatter="amountFormatter">收支记录</th>
                <th data-field="reason">收支原因</th>
                <th data-field="earningType" data-formatter="typeFormatter">分成类型</th>
                <th data-field="state" data-formatter="stateFormatter">交易状态</th>
                <th data-field="fkOrderId">交易单号</th>
                <th data-field="addTime">创建时间</th>
            </tr>
        </thead>
    </table>

</div>
</body>
<!-- 全局js -->
<script src="../../js/jquery.min.js?v=2.1.4"></script>
<script src="../../js/bootstrap.min.js?v=3.3.6"></script>
<script src="../../js/plugins/autoComplete/jquery.autocomplete.js"></script>
<!-- 自定义js -->
<script src="../../js/content.js?v=1.0.0"></script>


<!-- Bootstrap table -->
<script src="../../js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="../../js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="../../js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!--MVVM框架-->
<script type="text/javascript" src="../../js/plugins/knockout/knockout-3.4.2.js"></script>
<script type="text/javascript" src="../../js/plugins/knockout/knockout.mapping-latest.js"></script>

<!-- layerDate plugin javascript -->
<script src="../../js/plugins/layer/laydate/laydate.js"></script>

<script type="text/javascript" src="../../js/common/auth.js"></script>

<script type="text/javascript">
     var __listUrl = "/appAgent/getMemberEarning";  //post 获取列表
    var __listMemberUrl = "/appMember/read/list";  //put 获得所有用户详情
    var maxHeight = top.document.body.clientHeight * 0.8 ; //文档高度的80%
    //获取父页面传过来的参数并封装成一个对象
    function GetRequest() {
        var url =location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if(url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
        
    var getBalance = function (fkMemId) {
        $$ajax({
            url: "/appAgent/getBlance",
            type: "post",
            data:JSON.stringify({"fkMemId":fkMemId}),
            contentType: 'application/json',
            success: function (response) {
                if (response.code == 200) {
                    console.log("查询成功");
                    //$("#accountName").text(response.data.agentName);
                        var name =response.data.name;
                        var balance = response.data.balance;
                        $("#name").val(name);
                        $("#balance").val(balance/100);
                       
                } else if (response.code == 401) {
                        window.location.href = "login.html";
                }
            },
            error: function (textStatus) {

                alert(textStatus);
                window.location.href = "login.html";
                console.error(textStatus);
            },
            complete: function (XMLHttpRequest, statusText) {
                if (statusText == 'timeout') {
                    xhr.abort();
                    alert('Time out');
                }
            },
        });
    }


    //初始化
    $(function () {
     
        tableInit.Init();
    });
    var koModel={
        searchModel:{
             fkMemId:ko.observable(),
             fkRememId:ko.observable(),
        }
    };
    //初始化表格
    var tableInit = {
        Init: function () {
            function queryParams(param){
                var unmapped = ko.mapping.toJS(koModel.searchModel);
                var pa = { pageSize: param.limit, pageNum : param.offset/param.limit+1 }
                pa.orderBy = "add_time";
                var reqParam = GetRequest();
                var fkMemId = reqParam['fkMemId'];
                pa.fkMemId = fkMemId;
                getBalance(fkMemId);
                //alert(JSON.stringify($.extend(pa,unmapped)));
                return $.extend(pa,unmapped);
            }

            $("#tb_dept").bootstrapTable({
                url: __listUrl,
                method: 'post',                      //请求方式（*）
                contentType:'application/json',
                toolbar: '#toolbar',                //工具按钮用哪个容器
                queryParams: queryParams,           //传递参数（*）
                pagination: true,                   //是否显示分页（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                paginationHAlign:"right",
                uniqueId:"id",
                pageNumber: 1,                      //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],       //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                cache:false,
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: false,                //是否启用点击选中行
                showToggle: false,
                responseHandler:function(res){
                    if(res.code==401){
                        top.window.location.href=top.window.location.origin+"/login.html";
                    }
                    return {
                        "total":res.data.totalCount,
                        "rows":res.data.rows
                    }
                }
            });
        }
    };
	
	 /**
     每行的操作按钮
     */
	function typeFormatter(value, row, index){
    	if(value&&value==1){
    		return "用户注册分成";
    	}else{
    		return "用户消费分成"
    	}
    }
    
    function amountFormatter(value, row, index){
    	if(value){
    		return value/100;
    	}	
    }
    
    function stateFormatter(value, row, index){
    	if(value&&value==1){
    		return "完成";
    	}else if(value==2){
    		return "正在进行";
    	}else{
    		return "失败";
    	}
    }    
	function getTable(){
		return $("#tb_dept");
	}
    function getSelections(){
        return getTable().bootstrapTable('getSelections');
    }
    function refreshTable(){
        getTable().bootstrapTable("refresh");
    }

    function formatMemberParams(param) {
        return JSON.stringify({ pageNum: 1, pageSize: 10, name: param.name });
    }
</script>

</html>